package com.dong.webDriver;

import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ToupiaoTest {
    Random random = new Random();

    @BeforeClass
    public static void init() {
        System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome.app/Contents/MacOS/chromedriver");
    }

    @Test
    public void test() {
        List<String> emailList = new ArrayList<>();

        WebDriver driver = new ChromeDriver();
        driver.get("https://k.git-online.org/app/index.php?c=entry&do=toupiao/playerdetails&m=xiaof_toupiao&i=1&sid=34421&id=598&wxref=mp.weixin.qq.com");
        driver.manage().deleteAllCookies();
        // 找到并点击注册按钮
        driver.findElement(By.linkText("注册账号")).click();

        // 随机注册
        String email = "dong" + random.nextInt(999999999) + "@qq.com";
        System.out.println("email === " + email);
        emailList.add(email);
        driver.findElement(By.name("username")).sendKeys(email);
        driver.findElement(By.name("password")).sendKeys("123456");
        driver.findElement(By.name("repassword")).sendKeys("123456");
        driver.findElement(By.className("register-basic")).click();

        // 点击投票
        driver.findElement(By.className("vote-btn")).click();
        driver.quit();
    }
}
